home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3027 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: i = atoi(NULL);
  5. Date: Thu, 25 Jan 96 14:15:57 GMT
  6. Organization: none
  7. Message-ID: <822579357snz@genesis.demon.co.uk>
  8. References: <DKwCsG.IGD@cs.openu.ac.il> <96009.103802DSEAMA41@portland.caps.maine.edu> <30F7F466.F43@imsisoft.com> <DLnJpF.ApL@cs.openu.ac.il>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <DLnJpF.ApL@cs.openu.ac.il>
  15.            shimoco@mail.tlm.openu.ac.il "Shimon Cohen" writes:
  16.  
  17. >Thats right !
  18. >I called  atoi like this:
  19. >i = atoi (strtok (input_str, ",");
  20. >My compiler (BC4.0) docs says:  "If no conversion could be performed,
  21. >zero is returned." . I used this fact and it works fine. but not under
  22. >the unix machine of my teacher :-(
  23.  
  24. This hinges on what is meant by "If no conversion could be performed".
  25. What it actually means is if the contents of the string passed to
  26. atoi() is not recognised as a number e.g. atoi("A1234") would return 0. You
  27. are still required to pass atoi() a pointer to a valid string, a null
  28. pointer doesn't qualify. Your system probably accepts it because it
  29. doesn't support the hardware protection required to trap an invalid
  30. null pointer dereference whereas the Unix system does.
  31.  
  32. Thank the Unix system - it helped you to identify and correct a bug in your
  33. program.
  34.  
  35. -- 
  36. -----------------------------------------
  37. Lawrence Kirby | fred@genesis.demon.co.uk
  38. Wilts, England | 70734.126@compuserve.com
  39. -----------------------------------------
  40.